﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OracleClient;
using Oracle.DataAccess;
using EntitiesLayer;
using EntitiesLayer.Entities;
using System.Data;

namespace DataLayer.DAO
{
    public class TrabajadorDAO
    {
        private Connection.Connection cn;
        private OracleConnection objCn;

        public TrabajadorDAO()
        {
            cn = new Connection.Connection();
            objCn = cn.Conecta();
        }
        public List<Trabajador> getAllTrabajadores()
        {
            List<Trabajador> list = new List<Trabajador>();

            using (OracleCommand cmd = new OracleCommand("getalltrabajadores", objCn))
            { 
                cmd.CommandType = CommandType.StoredProcedure;
                OracleParameter refParameter = new OracleParameter();
                refParameter.ParameterName = "RECORDSET";
                refParameter.OracleType = OracleType.Cursor;
                refParameter.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(refParameter);
                try
                {
                    objCn.Open();

                    OracleDataReader dr = cmd.ExecuteReader();

                    while (dr.Read())
                    {
                        Trabajador p = new Trabajador();
                        p.Id_persona = Convert.ToInt32(dr[0]);
                        p.Id_cargo = Convert.ToInt32(dr[1]);
                        p.Usuario = Convert.ToString(dr[2]);
                        p.Password = Convert.ToString(dr[3]);

                        list.Add(p);
                    }
                }
                catch (Exception ex)
                {
                    objCn.Dispose();
                }
                finally
                {
                    objCn.Close();
                }
            }
            return list;
            }
        }

}
